Central Article

The mDialogBox Component: Not Your Father's Dialog Box


Table of Contents

  1. Introduction
  2. Understanding the mDialogBox Structure
  3. Putting mDialogBox to Work
  4. mDialogBox Tips

Understanding the mDialogBox Structure

It's easiest to understand the structure of the mDialogBox component after you've seen what it can do. Figure 1 shows a fairly full-featured example, albeit mocked up with simple graphics. Because this dialog box has two sections (red and green), the user is given a drop-down menu from which to select one page to view. (The user sees only one page at a time.) Notice that because the two clips are sized differently, the dialog box will accommodate, by tweening this difference at the time the user makes a selection. The setting you make for the "grow from" parameter—left, right, middle—determines how this tween behaves. Finally, you can specify other details, including something other than "title of dialog" for the title and whether or not a close box appears. If you do forgo the close box you'll probably want to give the user a way to issue the doClose() script. Because you can populate the dialog box with clips, they can contain other components and easily issue any script you want (including doClose()—though be sure to check out the "mDialogBox Tips" page for ways to reference the dialog box from inside the dialog box).

One dialog box can include multiple pages accessible to the user through a drop-down menu.

Figure 1. One dialog box can include multiple pages accessible to the user through a drop-down menu.

Populating mDialogBox

You can populate mDialogBox manually, either by using the parameters tab in the Property inspector or by writing scripts. Like many other components, mDialogBox supports parallel arrays: one for labels and one for data. That is, the labels are what the user sees in the drop-down menu (red_label and green_label in Figure 1) and the data are strings that match the corresponding library items' linkage identifiers. To set the linkage identifier for the clip you want to appear in the dialog box, select the symbol in the library window and choose Linkage from the Library's options menu or the context menu when you right-click it (Control-click on Mac). If you then select Export for ActionScript you'll be able to set an identifier (see Figure 2).

Symbols used within the mDialogBox component need linkage properties set as shown.

Figure 2. Symbols used within the mDialogBox component need linkage properties set as shown.

You can manually populate the mDialogBox component's Labels and Data parameters through the Property inspector (as shown in Figure 3). Alternatively and, really, more optimally, you can populate using scripts by first making a Central DataProvider—basically an array full of ActionScript objects, each with a Label and Data property. Here's the script to make a DataProvider and populate mDialogBox for the simple examples shown so far:

var dp = new Central.DataProviderClass();
dp.addItem({label:"red_label", data: "red_linkage"});
dp.addItem({label:"green_label", data: "green_linkage"});
myDialog.setDataProvider(dp);

In order for that last line to work you need to give the mDialogBox component an instance name, "myDialog".

Although populating using a DataProvider is preferable, you can also populate mDialogBox manually with the Parameters tab of the Property inspector.

Figure 3. Although populating using a DataProvider is preferable, you can also populate mDialogBox manually with the Parameters tab of the Property inspector.

(+) View larger

Using a One-Screen Dialog Box

There are other options too; after all, you don't have to use a multiscreen dialog box. If you want just one screen, you only need to set the parameter for "single content linkage id" (or create a DataProvider with a single item). A multiscreen dialog box is appropriate whenever there are many settings for the user to make—perhaps more options than comfortably fit on one small screen—or when the options fall into natural groupings. Use a single-screen dialog box when you need to present the user with a simple prompt, such as "Are you sure you want to clear the history?" followed by Yes and No buttons.

Deciding on Modality

Regardless whether you use a single- or multiscreen dialog box, you need to decide whether you want the dialog box to be modal or not. A modal dialog box, when displayed, disables all other interactive elements, such as buttons and text entry fields. In addition, the modal option covers everything under the dialog box with a gray transparent cover. The user cannot interact with the rest of your application—just the dialog box—when a modal dialog box is open. Although the default modal setting is false, I think most cases call for a modal dialog box. Without the modal option there are few benefits to mDialogBox over other Macromedia Central components such as the AccordionTab or ExpandingPod. In any event, you can set modal to true or false using the Parameters tab in the Property inspector or through the initially undocumented method setIsModal()—that is, myDialog.setIsModal(true) or myDialog.setIsModal(false).

Opening and Closing the Dialog Box

Without picking a favorite method, I definitely need to show you doClose() and doOpen(). I mention doClose() first because, without it, any dialog box you place on the Stage appears when the application first loads. Most likely you'll only want the dialog box to appear once the user selects Preferences from a menu. So just stick doClose() in your initialization scripts and later issue doOpen(). The following complete example displays a dialog box when the user selects Preferences from the menu:

myDialog.doClose()
showPreferences=function(){
  myDialog.doOpen();
  //probably also populate the dialog with the current preferences
}
Central.initApplication(this,this);

In order for the preferences to even appear in the menu, your product.xml file needs the attribute hasPreferences="true" inside the application tag.

Now that you know the basic possibilities of the mDialogBox component, you can look at a couple examples that exploit it for specific needs.